import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {LoginGuard} from './guards/login.guard';
import {LogoutGuard} from './guards/logout.guard';
import {UserRoleGuard} from './guards/user-role.guard';
import {UserTypeResolve} from './resolves/user-type.resolve';
import {LoanGuard} from './guards/loan.guard';
import {UserAccountGuard} from './guards/user-account.guard';
import {RechargeGuard} from './guards/recharge.guard';
import {LeaveGuard} from './guards/leave.guard';

const routes: Routes = [
  /** 公开的路由 **/
  {path: '', loadChildren: './tabs/tabs.module#TabsPageModule'},
  // 登录
  {
    path: 'login',
    loadChildren: './pages/login/login.module#LoginPageModule',
    canActivate: [LogoutGuard] // 退出状态守卫(针对本路由)
  },
  // 注册
  {path: 'registry', loadChildren: './pages/registry/registry.module#RegistryPageModule'},
  // 新手指南(介绍)
  {path: 'novice-guide', loadChildren: './pages/novice-guide/novice-guide.module#NoviceGuidePageModule'},
  // 资金存管(介绍)
  {path: 'fund-custody', loadChildren: './pages/fund-custody/fund-custody.module#FundCustodyPageModule'},
  // 资金存管(陕坝版)
  {path: 'fund-custody-new', loadChildren: './pages/fund-custody-new/fund-custody-new.module#FundCustodyNewPageModule'},
  // 保障体系(介绍)
  {path: 'guarantee-system', loadChildren: './pages/guarantee-system/guarantee-system.module#GuaranteeSystemPageModule'},
  // 标的详细信息
  {
    path: 'bid',
    loadChildren: './pages/bid/bid.module#BidPageModule'
  },
  // 标的投资页
  // {path: 'bid/purchase', loadChildren: './pages/bid-purchase/bid-purchase.module#BidPurchasePageModule'},
  // 标的信息－借款详情
  {path: 'bid/detail', loadChildren: './pages/bid-detail/bid-detail.module#BidDetailPageModule'},
  // 标的信息－投标记录
  {path: 'bid/record', loadChildren: './pages/bid-record/bid-record.module#BidRecordPageModule'},
  // 标的信息－回款计划
  {path: 'bid/plan', loadChildren: './pages/bid-plan/bid-plan.module#BidPlanPageModule'},
  // 帮助中心
  {path: 'help-center', loadChildren: './pages/help-center/help-center.module#HelpCenterPageModule'},
  // 帮助中心二级菜单
  {path: 'help-center-second', loadChildren: './pages/help-center-second/help-center-second.module#HelpCenterSecondPageModule'},
  // 帮助中心详情页面
  {path: 'help-center-detail', loadChildren: './pages/help-center-detail/help-center-detail.module#HelpCenterDetailPageModule'},
  // 关于我们
  {path: 'about-us', loadChildren: './pages/about-us/about-us.module#AboutUsPageModule'},
  // 找回密码
  {path: 'retrieve-password', loadChildren: './pages/retrieve-password/retrieve-password.module#RetrievePasswordPageModule'},
  /** 需要登录权限的路由 **/
  {
    path: 'auth',
    children: [
      // 系统消息列表
      {path: 'system-message', loadChildren: './pages/system-message/system-message.module#SystemMessagePageModule'},
      // 实名认证(开通存管)
      {
        path: 'user-account',
        loadChildren: './pages/user-account/user-account.module#UserAccountPageModule',
        canActivate: [UserAccountGuard], // 资金存管状态守卫(已开通资金存管不可进入)
        resolve: {
          userType: UserTypeResolve
        }
      },
      // 存管银行信息页(解除授权)
      {
        path: 'user-account-unbind',
        loadChildren: './pages/user-account-unbind/user-account-unbind.module#UserAccountUnbindPageModule',
        canActivate: [UserRoleGuard]
      },
      // 银行卡管理
      {path: 'user-card', loadChildren: './pages/user-card/user-card.module#UserCardPageModule', canActivate: [UserRoleGuard]},
      // 账户充值
      {
        path: 'user-recharge',
        loadChildren: './pages/user-recharge/user-recharge.module#UserRechargePageModule',
        canActivate: [
          RechargeGuard, // 限制企业用户充值
          UserRoleGuard
        ]
      },
      // 账户提现
      {
        path: 'user-cash-withdrawal',
        loadChildren: './pages/user-cash-withdrawal/user-cash-withdrawal.module#UserCashWithdrawalPageModule',
        canActivate: [UserRoleGuard]
      },
      // 交易记录
      {path: 'user-records', loadChildren: './pages/user-records/user-records.module#UserRecordsPageModule', canActivate: [UserRoleGuard]},
      // 交易记录详情
      {
        path: 'user-records-detail',
        loadChildren: './pages/user-records-detail/user-records-detail.module#UserRecordsDetailPageModule',
        canActivate: [UserRoleGuard]
      },
      // 回款计划(用户)
      {
        path: 'user-lend-plan',
        loadChildren: './pages/user-lend-plan/user-lend-plan.module#UserLendPlanPageModule',
        canActivate: [UserRoleGuard]
      },
      // 我的出借
      {path: 'user-lend', loadChildren: './pages/user-lend/user-lend.module#UserLendPageModule', canActivate: [UserRoleGuard]},
      // 我的出借－出借详情
      {
        path: 'user-lend-detail',
        loadChildren: './pages/user-lend-detail/user-lend-detail.module#UserLendDetailPageModule',
        canActivate: [UserRoleGuard]
      },
      // 出借详情－账单列表
      {
        path: 'user-lend-bill',
        loadChildren: './pages/user-lend-bill/user-lend-bill.module#UserLendBillPageModule',
        canActivate: [UserRoleGuard]
      },
      // 出借详情－账单列表(用户回款计划)－账单详情
      {
        path: 'user-lend-bill-detail',
        loadChildren: './pages/user-lend-bill-detail/user-lend-bill-detail.module#UserLendBillDetailPageModule',
        canActivate: [UserRoleGuard]
      },
      // 优惠红包
      {path: 'user-bonus', loadChildren: './pages/user-bonus/user-bonus.module#UserBonusPageModule'},
      // 还款计划(用户)
      {
        path: 'user-loan-plan',
        loadChildren: './pages/user-loan-plan/user-loan-plan.module#UserLoanPlanPageModule',
        canActivate: [UserRoleGuard]
      },
      // 我的借款
      {path: 'user-loan', loadChildren: './pages/user-loan/user-loan.module#UserLoanPageModule', canActivate: [UserRoleGuard]},
      // 我的借款－借款详情
      {
        path: 'user-loan-detail',
        loadChildren: './pages/user-loan-detail/user-loan-detail.module#UserLoanDetailPageModule',
        canActivate: [UserRoleGuard]
      },
      // 借款详情－账单列表
      {
        path: 'user-loan-bill',
        loadChildren: './pages/user-loan-bill/user-loan-bill.module#UserLoanBillPageModule',
        canActivate: [UserRoleGuard]
      },
      // 借款详情－账单列表(用户还款计划)－账单详情
      {
        path: 'user-loan-bill-detail',
        loadChildren: './pages/user-loan-bill-detail/user-loan-bill-detail.module#UserLoanBillDetailPageModule',
        canActivate: [UserRoleGuard]
      },
      // 借款流程
      {
        path: 'loan',
        loadChildren: './pages/loan/loan.module#LoanPageModule',
        canActivate: [
          LoanGuard // 借款流程守卫(已包含角色守卫功能；1.未选择借款类型打开类型modal 2.借款已审批通过，不可进入)
        ]
      },
      // 借款申请
      {path: 'loan-apply', loadChildren: './pages/loan-apply/loan-apply.module#LoanApplyPageModule', canActivate: [UserRoleGuard]},
      // 上传资料
      {path: 'loan-upload', loadChildren: './pages/loan-upload/loan-upload.module#LoanUploadPageModule', canActivate: [UserRoleGuard]},
      // 安全中心
      {path: 'safety-center', loadChildren: './pages/safety-center/safety-center.module#SafetyCenterPageModule'},
      // 风险评估
      {path: 'risk-rating', loadChildren: './pages/risk-rating/risk-rating.module#RiskRatingPageModule'},
      // 会员信息(个人)
      {path: 'membership-info', loadChildren: './pages/membership-info/membership-info.module#MembershipInfoPageModule'},
      // 会员信息(企业)
      {
        path: 'membership-info-enter',
        loadChildren: './pages/membership-info-enter/membership-info-enter.module#MembershipInfoEnterPageModule'
      },
      // 手势解锁
      {
        path: 'gesture-lock',
        loadChildren: './pages/gesture-lock/gesture-lock.module#GestureLockPageModule'
      },
      // 我的头像
      {path: 'user-avatar', loadChildren: './pages/user-avatar/user-avatar.module#UserAvatarPageModule'}
    ],
    canActivateChild: [LoginGuard] // 登录状态守卫(针对子路由)
  },
  { path: 'fund-custody-new', loadChildren: './pages/fund-custody-new/fund-custody-new.module#FundCustodyNewPageModule' }

];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {
}
